﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YCMS.Domain.Abstract;
using YCMS.Domain.Entities;
using System.Data.Entity;

namespace YCMS.Domain.Concrete
{
    public class EFDockRepository : IDockRepository, IDisposable
    {
        public EfDbContext Context
        {
            get
            {
                return context;
            }
            set
            {
                context = value;
            }
        }
        private EfDbContext context;

        public IQueryable<Dock> Docks
        {
            get { return context.Dock; }
        }

        public void InsertDock(Dock dock)
        {
            context.Dock.Add(dock);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public Dock GetDockById(int id)
        {
            Dock dock = context.Dock.Find(id);
            return dock;
        }

        public void UpdateDock(Dock dock)
        {
            context.Entry(dock).State = System.Data.EntityState.Modified;
        }

        public void DeleteDock(Dock dock)
        {
            context.Dock.Find(dock.ID);
            context.Dock.Remove(dock);
        }

        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        } 

    }
}
